<!DOCTYPE html>
<html>
<head>
<script>
if (window.testRunner) {
    testRunner.dumpAsText();
    testRunner.setPopupBlockingEnabled(false);
    testRunner.overridePreference('WebKitSupportsMultipleWindows', false);
    testRunner.waitUntilDone();
}

function click(elmt)
{
    var event = document.createEvent('MouseEvent');
    event.initEvent('click', true, true);
    elmt.dispatchEvent(event);
}

function runTest()
{
    if (window.testRunner)
        var windowCount = testRunner.windowCount();
    var link = document.getElementById("link");
    click(link);
    if (window.testRunner) {
        if (windowCount != testRunner.windowCount())
            document.writeln('FAIL: Popup opened in a new window');
        else
            document.writeln('PASS: Popup opened in the same window');
        testRunner.notifyDone();
    }
}

window.addEventListener('load', runTest, true);
</script>
</head>
<body>
You need popups to be enabled to run this test.
<a id="link" target="_blank" href="resources/popup.html">Click me!</a>
</body>
</html>
